<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>

<script type="text/javascript">
	
	//验证
	$(function() {
		//绑定回车事件
		$(':input').bind('keyup', function(event){
		   if (event.keyCode=="13"){
		   		$("#tiJiaoBiaoDan").submit();
		   }
		});
		
		//表单验证使用属性validate进行验证
		$.metadata.setType("attr","validate");
		$("#tiJiaoBiaoDan").validate({
			rules: {
				username: {
					required: true,
					minlength:2,
					chinese:24,
					maxlength: 20
				},
				email:{
					required: true,
					email:true,
					remote: 'checkEmail.ajax'
				},
				password:{
					required: true,
					minlength:6,
					maxlength:20,
					remote:'checkIsHostPassword.htm'
				},
				confirm_password:{
					equalTo:'#password'
				},
				agree:{
					required:true
				}
			},
			messages: {
				username: {
					maxlength: "姓名不能超过20个字符",
					minlength:"姓名为2个以上汉字",
					chinese:"姓名为2个以上汉字"
				},
				email:{
					required: "Email不能为空",
					email:"请输入正确的email格式",
					remote: "Email已存在"
				},
				password:{
					required: "钥匙不能为空",
					remote:"您输入钥匙和户主的一样，请重新输入或重新选择"
				},
				confirm_password:{
					equalTo:'两次输入钥匙必须相同'
				}
			},
			submitHandler: function() {
				//保存家基本资料的修改
				var email = $("#email").val();
				var role = $("#role").val();
				var password = $("#add_family_member").find("#password").val();
				var username = $("#username").val();
				$("#saveButton").attr("onclick","");
				$.post("addFamilyMember.htm", {
					username : username,
					password : password,
					email 	 : email,
					role 	 : role
				},function(data){
					if (data == 'success') {
						my_family_navigate();
						$("#content_detail").load("memberInfo.htm",
							function() {
								showOtherTab('newNews3');
								refreshParentsAvatar();
								$("#jiaZiLiao1").attr("class", "current");
						});
					}
				});
			}
		});
	});
	
	//根据下拉框选择钥匙
	function sameKey(){
		var key = $("#isSameKey").val();
		if(key=="same"){
			$("#removePassword").remove();
			$("#removeConfirm_password").remove();
		}else{
			$("#add_family_member").append($("#key_not_Same").html());
		}
	}
</script>

	<form action="" id="tiJiaoBiaoDan" >
	<div class="success" id="base_info_tip_success" style="display: none; margin-left: 32px;">
		<img alt="修改成功" src="<%=basePath%>images/home_images/ico29.png">家的成员添加成功
	</div>
	<div class="h_dataInfo">
		<table id="add_family_member">
			<tr>
			<td class="data_text">家庭角色：</td>
			<td>
				<c:if test="${sessionScope.member.role=='01' }">
					<input type="hidden" id="role" value="02">
					妈妈
				</c:if>
				<c:if test="${sessionScope.member.role=='02' }">
					<input type="hidden" id="role" value="01">
					爸爸
				</c:if>
			</td>
		</tr>
		<tr>
			<td class="data_text">登录邮箱：</td>
			<td><input type="text" id="email" name="email"/>
			</td>
		</tr>
		<tr>
			<td class="data_text">姓名：</td>
			<td><input type="text" id="username" name="username" /> </td>
		</tr>
		<tr>
			<td class="data_text">钥匙：</td>
			<td id="isHostKey">
				<select id="isSameKey" onchange="sameKey()">
					<option value="same">和户主使用同一把钥匙</option>
					<option value="notSame">自己创建钥匙</option>
				</select>
			</td>
		</tr>
		</table>
	</div>
	<table>
		<tr>
			<td width="130"></td>
			<td width="524">
				<div class="h_button w75 mt15"><strong id="saveButton" onclick="javascript:$('#tiJiaoBiaoDan').submit();">保存设置</strong></div>
			</td>
		</tr>
	</table>
</form>
<table id="key_not_Same" style="display: none;">
	<tr id="removePassword">
		<td class="data_text">钥匙：</td>
		<td><input type="password" id="password" name="password"/> </td>
	</tr>
	<tr id="removeConfirm_password">
		<td class="data_text">重复钥匙：</td>
		<td><input type="password" id="confirm_password" name="confirm_password" /> </td>
	</tr>
</table>

